% read the file in the format of min-maxer triangles
% return Nx3 triangels, each row consists of the triangles
function [sites, edges, triangles]=readTriangles(fileName)

[sites, edges]=readEdges(fileName);

numSites=size(sites,1);
neighbors=cell(numSites,1);
numEdges=size(edges,1);
triangles=[];

for e=1:numEdges
    edge_id=edges(e,:)+1;
    
    %if the edge connects vertices that share the same neighbor, add one
    %triangle
    triangles=findTriangles(edge_id, neighbors, triangles);
    
    %update neighbors information based on the new edge
    neighbors{edge_id(1)}=[neighbors{edge_id(1)}, edge_id(2)];
    neighbors{edge_id(2)}=[neighbors{edge_id(2)}, edge_id(1)];
end

return;


 %if the edge connects vertices that share the same neighbor, add one triangle
function triangles=findTriangles(edge_id, neighbors, triangles)
    neighbor1=neighbors{edge_id(1)};
    neighbor2=neighbors{edge_id(2)};
    temp=intersect(neighbor1, neighbor2);
    if sum(temp)~=0
        for i=1:length(temp)
            triangles=[triangles; temp(i), edge_id];
        end
    end
return;
